local meta = FindMetaTable("Player");
local additionalData = {};

function GM:AddDataField(name, default)
	additionalData[name] = default;
end;

function meta:LoadData()
	local path = "LightRP2/data/" .. string.sub(self:SteamID(), 11) .. ".txt";
	
	if (file.Exists(path)) then
		local data = glon.decode(file.Read(path));
		
		self.lgtrp = data;
	else
		self.lgtrp = {};
	end;
	
	for field, default in pairs(additionalData) do
		if (self.lgtrp[field] == nil) then
			self.lgtrp[field] = default;
		end;
	end;
	
	self.tempFlags = {};
	self.sandboxLimits = {};
	
	local limits = GAMEMODE:GetConfig("sandboxLimits");
	
	for k, v in pairs(limits) do
		self.sandboxLimits[k] = {};
	end;
end;

function meta:SaveData()
	local data = glon.encode(self.lgtrp);
	local path = "LightRP2/data/" .. string.sub(self:SteamID(), 11) .. ".txt";
	
	file.Write(path, data);
end;

function meta:GiveItem(unique, amount)
	local data = GAMEMODE:GetItemData(unique);
	
	if (data) then
		local weight = data.weight;
	end;
end;

function meta:RemoveItem(unique, amount)
	local data = GAMEMODE:GetItemData(unique);
	
	if (data) then
		local weight = data.weight;
	end;
end;

function meta:AddSandboxLimit(type, entity)
	self.sandboxLimits[type] = self.sandboxLimits[type] or {};
	
	table.insert(self.sandboxLimits[type], entity);
end;

function meta:ReachedSandboxLimit(type)
	local limits = GAMEMODE:GetConfig("sandboxLimits")[type];
	local pLimit = self.sandboxLimits[type];
	
	for k, entity in pairs(pLimit) do
		if (!IsValid(entity)) then
			table.remove(pLimit, k);
		end;
	end;

	return #pLimit >= limits;
end;